import { N as request, V as getStorageSync } from './index-Cc4oxzDN.js';
import { a as getLoginFrom } from './platform.EIa5ETLd.js';

/**
 * 使用手机 + 验证码登录
 */
function userLogin(data) {
	// 自动添加平台标识
	const loginData = {
		...data,
		from: getLoginFrom()
	};

	console.log('手机验证码登录 - 平台标识:', loginData.from);

	return request.post('/member/auth/sms-login', loginData, {
		login: false
	})
}

/**
 * 使用手机 + 验证码登录  member/auth/send-sms-code
 */
function smsSend(data) {
	// 自动添加平台标识
	const smsData = {
		...data,
		from: getLoginFrom()
	};

	console.log('发送短信验证码 - 平台标识:', smsData.from);

	return request.post('/member/auth/send-sms-code', smsData, {
		login: false
	})
}

/**
 * userAuthSession   
 */
function userAuthSession(data) {
	// 自动添加平台标识
	const sessionData = {
		...data,
		from: getLoginFrom()
	};

	console.log('用户会话认证 - 平台标识:', sessionData.from);

	return request.post('/member/auth/auth-session', sessionData, {
		login: false
	})
}

/**
 * 支付宝小程序授权登录
 */
async function alipayMiniAppLogin(data) {
	console.log('alipayMiniAppLogin', data);

	// 自动添加平台标识和调试信息
	const loginData = {
		...data,
		from: getLoginFrom(),
		buyerId: data.buyerId || getStorageSync('buyer_id') || null
	};

	console.log('支付宝小程序登录 - 请求数据:', loginData);

	try {
		const res = await request.post('/member/auth/auth-alipay-miniapp-login', loginData, {
			login: false
		});
		console.log('alipayMiniAppLogin res', res);
		return res;
	} catch (error) {
		console.log('alipayMiniAppLogin error', error);
		return null;
	}
}



/**
 * 用户退出登录
 */
function userLogout() {
	console.log('调用退出登录API');

	return request.post('/member/auth/logout', {}, {
		login: true // 需要token验证
	})
}

export { userLogin as a, userLogout as b, alipayMiniAppLogin as c, smsSend as s, userAuthSession as u };
